package tr.edu.boun.phys.springmassmodel.UI.PropertiesWindow;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;

import tr.edu.boun.phys.springmassmodel.UI.ResourceManager;

public class ComboConstraints extends JComboBox implements ActionListener {

	private static final long serialVersionUID = 7525463339373946281L;
	
	private ResourceManager rm;
	
	public ComboConstraints(ResourceManager rm) {		
		this.rm = rm;
		String[] constraintString = { "no constraint", "y-only", "x-only", "no freedom" };
		DefaultComboBoxModel cbm = new DefaultComboBoxModel(constraintString);
		this.setModel(cbm);
		this.addActionListener(this);
	}
	
	public void actionPerformed(ActionEvent ae) {
		if( rm.getSelectedMass() != null ) {
			rm.getSelectedMass().setConstraint( this.getSelectedIndex() );		
		}
		
	}

}
